package com.cs.study.homework._0226;

public class Demo {
    public static void main(String[] args) {
        System.out.println("--------编写实现类进行测试---------");
        ComputeImpl compute = new ComputeImpl();
        System.out.println(compute.add(1, 2));
        System.out.println(compute.subtract(1, 2));
        System.out.println(compute.multiply(1, 2));
        System.out.println(compute.divide(1, 2));


        System.out.println("--------用局部内部类进行测试---------");
        Inner inner = new Demo().new Inner();
        System.out.println(inner.add(1, 2));
        System.out.println(inner.subtract(1, 2));
        System.out.println(inner.multiply(1, 2));
        System.out.println(inner.divide(1, 2));


        System.out.println("--------使用匿名内部类进行测试---------");
        ComputeImpl compute1 = new ComputeImpl() {
            @Override
            public double add(double a, double b) {
                return super.add(a, b);
            }

            @Override
            public double subtract(double a, double b) {
                return super.subtract(a, b);
            }

            @Override
            public double multiply(double a, double b) {
                return super.multiply(a, b);
            }

            @Override
            public double divide(double a, double b) {
                return super.divide(a, b);
            }
        };
        System.out.println(compute1.add(1, 2));
        System.out.println(compute1.subtract(1, 2));
        System.out.println(compute1.multiply(1, 2));
        System.out.println(compute1.divide(1, 2));

    }

    class Inner implements Compute {
        @Override
        public double add(double a, double b) {
            return a + b;
        }

        @Override
        public double subtract(double a, double b) {
            return a - b;
        }

        @Override
        public double multiply(double a, double b) {
            return a * b;
        }

        @Override
        public double divide(double a, double b) {
            return a / b;
        }
    }
}

class ComputeImpl implements Compute {
    @Override
    public double add(double a, double b) {
        return a + b;
    }

    @Override
    public double subtract(double a, double b) {
        return a - b;
    }

    @Override
    public double multiply(double a, double b) {
        return a * b;
    }

    @Override
    public double divide(double a, double b) {
        return a / b;
    }
}

interface Compute {
    double add(double a, double b);

    double subtract(double a, double b);

    double multiply(double a, double b);

    double divide(double a, double b);
}
